//
//  settingView.m
//  mark
//
//  Created by student5 on 2021/12/15.
//

#import <Foundation/Foundation.h>
#import "settingView.h"

@interface settingView()
@property(strong,nonatomic)UISwitch *isUseTimeSwitch;
@property(strong,nonatomic)UILabel *startSettingLabel;
@property(strong,nonatomic)UILabel *autoSettingLabel;
@property(nonatomic,strong)UIDatePicker *datePicker; //时间设置组件
@end

@implementation settingView

-(void)viewDidLoad{
    self.view.backgroundColor = [UIColor whiteColor];
    [self set_startSettingLabel];
    [self set_autoSettingLabel];
    [self set_switch];
    [self setupDatePicker];//设置提醒时间
    
}



//设置文字“默认设置”
-(void)set_startSettingLabel{
    self.startSettingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 200, 50)];
    self.startSettingLabel.text = @"默认设置：";
    self.startSettingLabel.font = [UIFont fontWithName:@"Arial" size:20.0f];
    self.startSettingLabel.textColor = [UIColor blackColor];
    [self.view addSubview:self.startSettingLabel];
}



//文字“设置默认提醒时间”
-(void)set_autoSettingLabel{
    self.autoSettingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 200, 50)];
    self.autoSettingLabel.text = @"设置默认提醒时间：";
    self.autoSettingLabel.font = [UIFont fontWithName:@"Arial" size:15.0f];
    self.autoSettingLabel.textColor = [UIColor blackColor];
    [self.view addSubview:self.autoSettingLabel];
}



//设置switch
-(void)set_switch{
    self.isUseTimeSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(170, 110, 100, 30)];
    //默认开启
    [self.isUseTimeSwitch setOn:true animated:true];
    //设置监听事件
    [self.isUseTimeSwitch addTarget:self action:@selector(SwitchChange:) forControlEvents:(UIControlEventValueChanged)];
    [self.view addSubview:self.isUseTimeSwitch];
}



//事件响应函数
-(void)SwitchChange:(UISwitch *)sender{
    if([sender isOn]){
        NSLog(@"switch is on!");
        //在此处添加功能设定
    }
    else{
        NSLog(@"switch is off!");
        //在此处添加功能设定
    }
}



- (void)setupDatePicker {
    //因为datapicker
    UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(20, 160, 150, 40)];
    /*NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]];*/
    
    //设置地区: zh-中国
    datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
    
    //设置日期模式(Displays month, day, and year depending on the locale setting)
    datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    // 设置当前显示时间
    [datePicker setDate:[NSDate date] animated:YES];
    
    self.datePicker = datePicker;
    
    [self.view addSubview:self.datePicker];
}
@end
